package mybag5;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class StudentList {

	static Set<Student> set = new HashSet<Student>();

	public static void main(String[] args) {

		set.add(new Student("何润杰", 12345));
		set.add(new Student("汪明伟", 12343));
		set.add(new Student("宫飞", 12342));
		set.add(new Student("宫飞", 12343));
	}

	// 添加学生对象
	public boolean add() {
		Scanner input = new Scanner(System.in);
		System.out.println("请输入添加的姓名：");
		String name = input.next();
		System.out.println("请输入学号！");
		int id = input.nextInt();
		if (set.contains(name) || set.contains(id)) {
			System.out.println("已经存在该学生！");
			return false;
		} else {
			set.add(new Student(name, id));
			System.out.println("添加成功");
			return true;
		}
	}

	// 删除指定学号的学生对象
	public boolean remove() {
		Scanner input = new Scanner(System.in);
		System.out.println("请输入要删除的学生学号！：");
		int delNo = input.nextInt();
		if (set.contains(delNo)) {
			set.remove(new Student(delNo));
			System.out.println("删除成功");
			return true;
		} else {
			System.out.println("该学号不合法！");
			return false;
		}

	}

	// 修改学生姓名
	public boolean update() {
		Scanner input = new Scanner(System.in);
		System.out.println("请输入要修改的学生学号");
		int num = input.nextInt();
		if (set.contains(num)) {
			set.remove(num);
			System.out.println("请输入修改后的姓名：");
			String name = input.next();
			set.add(new Student(name, num));
			System.out.println("修改成功");
			return true;
		} else {
			System.out.println("该学生不存在！");
			return false;
		}
	}

	// 4.根据姓名模糊查询学生
	public void Search() {
		Scanner input = new Scanner(System.in);
		System.out.println("请输入要查询的学生姓名：");
		String blurry = input.next();
		if (set.contains(blurry)) {
			for (Student student : set) {
				if (blurry.equals(student.getName())) {
					System.out.println(student.getId());
				}
			}
		} else {
			System.out.println("未找到这个学生");
		}

	}

	// 退出系统
	public void exist() {
		System.out.println("退出成功！");
		return;
	}
}
